package com.dts.evaluate.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.widget.ListView;

import com.dts.evaluate.R;

/**
 * Created by user on 2016/7/28.
 */
public class StrokListView extends ListView {
    private Paint paint;
    private int color;

    public StrokListView(Context context) {
        super(context);
        init(context);
    }

    public StrokListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public StrokListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context){
        color = ContextCompat.getColor(getContext(),R.color.list_devider_color);
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(1);
    }


    @Override
    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);

        paint.setColor(color);
        int width = getMeasuredWidth();
        int height = getMeasuredHeight();
        //先画 边框
        canvas.drawRect(0,0,width,height,paint);


    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //设置heightMeasureSpec为AT_MOST模式
        //heightMeasureSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
